package com.kksoft.readcm.activity;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.kksoft.readcm.a.Appconfig;
import com.kksoft.readcm.a.ItemAppObservable;
import com.kksoft.readcm.d.j;
import com.kksoft.readcm.objects.ab;
import com.kksoft.readcm.objects.GlobalVar;
import com.kksoft.readcm.objects.l;
import com.kksoft.readcm.objects.n;
import com.kksoft.readcm.objects.ReadListAdapter;
import com.kksoft.readcm.pro.R;

import java.util.Observable;

public class TagDirectory extends ListViewActivity
{
  private Button A = null;
  private View z = null;

  protected final boolean E()
  {
    return false;
  }

  protected final void a()
  {
    this.readlistadapter = new ab(this);
    this.listview.setAdapter(this.readlistadapter);
  }

  protected final void a(l paraml)
  {
  }

  protected final n a_()
  {
    n localn = Appconfig.getThis().getItemAppObservable().a();
    this.k = localn;
    if (this.k != null)
      this.k.d();
    return this.k;
  }

  protected final void b(Menu paramMenu)
  {
    super.b(paramMenu);
    paramMenu.add(-1, 25, 1, R.string.nm_current_list).setIcon(R.drawable.ic_menu_current_list);
    paramMenu.add(-1, 26, 2, R.string.nm_read_list).setIcon(R.drawable.ic_menu_archive);
  }

  protected final String e()
  {
    return "sortTags";
  }

  protected final String f()
  {
    return getString(R.string.nm_tags);
  }

  protected final String f(int paramInt)
  {
	  ReadListAdapter localo = this.readlistadapter;
    int i = c(paramInt);
    return (String)localo.getItem(i);
  }

  protected final String l()
  {
    return getString(R.string.le_tagdir_t);
  }

  protected final String m()
  {
    return getString(R.string.le_tagdir_m);
  }

  protected final String n()
  {
    return getString(R.string.le_learn_more_b);
  }

  protected final void o()
  {
    HelpActivity.a(6, this);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
		    Intent it = new Intent(TagDirectory.this, TagListActivity.class);
		    it.putExtra("tag", TagDirectory.this.f(position));
		    TagDirectory.this.startActivity(it);
		}
    	
    });
    unregisterForContextMenu(this.listview);
    this.edtFilter.setHint("Filter by tag");
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default:
      return super.onCreateDialog(paramInt);
    case 21:
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle(R.string.dg_sort_t)
      		.setSingleChoiceItems(com.kksoft.readcm.d.j.b(), H() - 1, new DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
				    TagDirectory.this.b(which + 1);
				    dialog.dismiss();
				}
      			
      		});

      Dialog dialog=builder.create();
  	dialog.setCanceledOnTouchOutside(true);
  	return dialog;
    }
  }

  protected void onSaveInstanceState(Bundle paramBundle)
  {
  }

  public final void u()
  {
	  if(readlistadapter.getCount() > 0)
          a(2);
      else
      if(readlistadapter.a() > 0)
      {
          if(readlistadapter.c())
              a(2);
          else
          if(A().length() > 0)
              a(4);
          else
              a(2);
      } else
      if(Appconfig.getThis().l())
          a(1);
      else
      if(i())
          a(6);
      else
          a(3);
      v();
  }

  public void update(Observable paramObservable, final Object paramObject)
  {
	  GlobalVar localh = GlobalVar.a(paramObject);
    if (localh != null)
    {
      runOnUiThread(new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			if ((GlobalVar.a(paramObject).a() == 1) || (GlobalVar.a(paramObject).a() == 2) || (GlobalVar.a(paramObject).a() == 3) || (GlobalVar.a(paramObject).a() == 22))
			    {
				TagDirectory.this.p = false;
				TagDirectory.this.a(0);
			    }
		}});
      super.update(paramObservable, paramObject);
    }
  }

  protected final String x()
  {
    return "filterTagDir";
  }
}